package com.nike.amoeba.ui.frg

import android.os.Bundle
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.ConvertUtils
import com.nike.amoeba.ext.init
import com.nike.amoeba.ext.loadServiceInit
import com.nike.amoeba.ext.showLoading
import com.nike.amoeba.weight.recyclerview.SpaceItemDecoration
import com.kingja.loadsir.core.LoadService
import com.nike.amoeba.adapter.TaskStockEpcAdapter
import com.nike.amoeba.base.BaseFragment
import com.nike.amoeba.databinding.BNotTitleRecyclerBinding
import com.nike.amoeba.viewmodel.TaskStockListModel

/**
 * @Author nike
 * @Date 2023/7/7 11:59
 * @Description
 */
class TaskStockEpcFrg : BaseFragment<TaskStockListModel, BNotTitleRecyclerBinding>(){

    val adapter: TaskStockEpcAdapter by lazy { TaskStockEpcAdapter(arrayListOf()) }

    lateinit var loadsir: LoadService<Any>

    override fun initView(savedInstanceState: Bundle?) {
        arguments?.let {
            mViewModel.orderId.set(it.getString("orderId"))
            mViewModel.batchNo.set(it.getString("batchNo"))
            mViewModel.code.set(it.getString("code"))
        }
        setToolBarTitle(mViewModel.batchNo.get()!!)
        //状态页配置
        loadsir = loadServiceInit(mDatabind.swipeRefresh) {

        }

        //初始化recyclerView
        mDatabind.recyclerView.init(LinearLayoutManager(context), adapter).let {
            it.addItemDecoration(SpaceItemDecoration(ConvertUtils.dp2px(20f), ConvertUtils.dp2px(20f), true))
        }

        mDatabind.swipeRefresh.isEnabled = false
    }

    override fun createObserver() {
        super.createObserver()
        mViewModel.listStockEpcBean.observe(viewLifecycleOwner, Observer {
            loadsir.showSuccess()
            adapter.setList(it)
            adapter!!.appendList(it)
        })
    }

    override fun lazyLoadData() {
        super.lazyLoadData()
        //设置界面 加载中
        loadsir.showLoading()
        mViewModel.onRequestEpc(mViewModel.orderId.get(), mViewModel.code.get())
    }

}